package com.baizhiedu.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * ClassName: TestMyBatis
 * Description:
 * Date: 2022/11/23 PM 1:47:07
 * <p>
 * project: spring5
 * package: com.baizhiedu.mybatis
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
public class TestMyBatis {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserDao userDao = sqlSession.getMapper(UserDao.class);

        User user = new User();
        user.setName("suns");
        user.setPassword("123456");
        userDao.save(user);

        sqlSession.commit();
    }
}
